package sanrenxing.dayEnd.backRepertoryTotal.service.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import sanrenxing.dayEnd.backRepertoryTotal.dao.FoundationDao;
import sanrenxing.dayEnd.backRepertoryTotal.domain.CashAccount;
import sanrenxing.dayEnd.backRepertoryTotal.domain.Foundation;
import sanrenxing.dayEnd.backRepertoryTotal.domain.ManagerSetup;
import sanrenxing.dayEnd.backRepertoryTotal.domain.TrusteeSetup;
import sanrenxing.dayEnd.backRepertoryTotal.service.FoundationBiz;

import java.util.HashMap;
import java.util.List;

/**
 * 功能：基金业务层实现类
 * 编写者：蒋玲苹
 * 日期：
 * 版本：1.0
 */
@Service
public class FoundationBizImpl implements FoundationBiz {
    @Autowired
    private FoundationDao foundationDao;
    /**
     * 将基金实体添加数据库基金表中
     *
     * @param foundation 基金对象
     * @return 0:添加失败,1:添加成功
     */
    @Override
    public int add(Foundation foundation) {
        return foundationDao.add(foundation);
    }

    /**
     * 从表中根据基金编号字符串删除一行数据
     * @param fundIds 基金编号字符串
     * @return 删除影响的行数(0 : 删除失败, 1 : 删除成功)
     */
    @Override
    public int delete(String fundIds) {
        //判断是否为批量删除
        if(fundIds.contains(",")){
            //对编号按“，”分割
            String[] strs=fundIds.split(",");
            //循环删除
            for(String str:strs){
                //调用方法删除
                foundationDao.delete(str);
            }
            //返回1
            return 1;
        }
        return foundationDao.delete(fundIds);
    }

    /**
     * 修改数据到foundation表
     *
     * @param foundation 员工对象
     * @return 0:修改失败,1:修改成功
     */
    @Override
    public int update(Foundation foundation) {
        return foundationDao.update(foundation);
    }

    @Override
    public List<CashAccount> ca() {
        return foundationDao.ca();
    }

    @Override
    public List<ManagerSetup> ms() {
        return foundationDao.ms();
    }

    @Override
    public List<TrusteeSetup> ts() {
        return foundationDao.ts();
    }

    /**
     * 按条件分页查询
     * @param foundation
     * @param row
     * @param page
     * @return
     */
    @Override
    public List<Foundation> queryAll(Foundation foundation, int row, int page) {
        HashMap<String,Object> map=new HashMap<>();
        map.put("foundation",foundation);
        map.put("start",page);
        map.put("end",(page+row));
        return foundationDao.queryAll(map);
    }

    /**
     * 按条件统计记录数
     *
     * @param foundation 统计条件
     * @return 记录行数据
     */
    @Override
    public int count(Foundation foundation) {
        return foundationDao.count();
    }

}
